<% @proposals.each do |proposal| %>
  (function() {
    var $proposalVotesCount = $('#proposal-<%= proposal.id %>-votes-count');

    if($proposalVotesCount[0]) {
      morphdom($proposalVotesCount[0], '<%= j(render partial: "decidim/proposals/proposals/votes_count", locals: { proposal:, from_proposals_list: @from_proposals_list }).strip.html_safe %>');
    }

    var $proposalVoteButton = $('#proposal-<%= proposal.id %>-vote-button');

    if($proposalVoteButton[0]) {
      morphdom($proposalVoteButton[0], '<%= j(render partial: "decidim/proposals/proposals/vote_button", locals: { proposal:, from_proposals_list: @from_proposals_list }).strip.html_safe %>');
    }
  })();
<% end %>

<% if vote_limit_enabled? %>
  (function() {
    var $remainingVotesCount = $('div[data-remaining-votes-count="true"]');
    var $notVotedButtons = $('*[data-proposal-vote-button="true"]').not('[id^=vote_button-]');

    if($remainingVotesCount[0]) {
      morphdom($remainingVotesCount[0], '<%= j(render partial: "decidim/proposals/proposals/remaining_votes_count").strip.html_safe %>');
    }

    <% if remaining_votes_count_for_user == 0 %>
      $notVotedButtons.attr('disabled', true);
    <% else %>
      $notVotedButtons.attr('disabled', false);
    <% end %>
  }());
<% end %>

<% if show_voting_rules? %>
  (function() {
    var $remainingVotesNotification = $('#remaining-votes-notification');
    var $exitProposalModal = $('#exit-proposal-notification');
    var $votingRules = $('.voting-rules');
    var $votingRulesNode = $('.item_voting_rules')

    if($votingRules[0]) {
      morphdom($votingRules[0], '<%= j(render partial: "decidim/proposals/proposals/voting_rules").strip.html_safe %>');
    }

    <% if minimum_votes_per_user_enabled? && remaining_minimum_votes_count_for_user.zero? %>
      $votingRulesNode.prepend(`<%= j(render partial: "decidim/proposals/proposals/notification_alert_box").strip.html_safe %>`)
    <% end %>
    if ($exitProposalModal[0]) {
      morphdom($exitProposalModal[0], '<%= j(render partial: "decidim/proposals/proposals/exit_modal").strip.html_safe %>')
      if(window.Decidim.currentDialogs["exit-proposal-notification"] && window.Decidim.currentDialogs["exit-proposal-notification"].dialog) {
        window.Decidim.currentDialogs["exit-proposal-notification"].dialog.innerHTML = $exitProposalModal[0].innerHTML;
      }
    }

    if ($remainingVotesNotification[0]) {
      morphdom($remainingVotesNotification[0], '<%= j(render partial: "decidim/proposals/proposals/remaining_votes_notification").strip.html_safe %>');
    }
  }());
<% end %>
